<?php


namespace App\Models;


use Illuminate\Database\Eloquent\Model;

class ShopWithdrawal extends Model
{
    protected $table = 'sp_shop_withdrawal';
    protected $primaryKey = 'id';
    public $timestamps = false;

    const WITHDRAWAL_AMOUNT_LIMIT = 0.1;//提现最低限制(单位元)
    const WITHDRAWAL_EXAMINE_MOBILE_CODE = '';//财务提现审核短信验证手机号

    const WITHDRAWAL_TYPE_ALIPAY = 1; //支付类型  1支付宝

    const WITHDRAWAL_STATUS_REVIEWED = 1; //待审核
    const WITHDRAWAL_STATUS_TRANS_SUCCESS = 2; //已入账
    const WITHDRAWAL_STATUS_TRANS_FAIL = 3; //未入账
    const WITHDRAWAL_STATUS_REFUSE = 4; //提现拒绝

    const WITHDRAWAL_TRANS_STATUS_FAIL = 1; //转账状态 1失败
    const WITHDRAWAL_TRANS_STATUS_SUCCESS = 2; //转账状态 2成功

    const WITHDRAWAL_TYPE_LIST = [
        1 => '支付宝',
    ];
    const WITHDRAWAL_STATUS_LIST = [
        1 => '待审核',
        2 => '已入账',
        3 => '未入账',
        4 => '提现拒绝',
    ];

    public static function account($member_id){
        $data['balance'] = ShopUser::where(['member_id'=>$member_id])->value('shop_balance');
        $data['frozen'] = ShopWithdrawal::where(['member_id'=>$member_id,'status'=>ShopWithdrawal::WITHDRAWAL_STATUS_REVIEWED])->sum('withdrawal_amount');
        return $data;
    }
}
